package com.nuanshui.heatedloan.controller.display.credit;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.nuanshui.framework.lang.SysStringUtils;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.controller.BaseController;
import com.nuanshui.heatedloan.credit.facade.PayOrderInfoService;
import com.nuanshui.heatedloan.credit.facade.third.party.RiskManagerInteractionService;
import com.nuanshui.heatedloan.credit.form.PayOrderInfoForm;
import com.nuanshui.heatedloan.credit.request.RaiseLimitRequest;
import com.nuanshui.heatedloan.credit.request.RiskSelectRequest;
import com.nuanshui.heatedloan.credit.response.RiskSelectResponse;
import com.nuanshui.heatedloan.credit.vo.PayOrderInfoVO;
import com.nuanshui.heatedloan.pageable.Pager;
import com.nuanshui.heatedloan.userinfo.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zss
 * @date 2017/6/29 14:37
 * @description
 * @Since
 */
@RequestMapping("credit/order")
@RestController
public class PayOrderInfoController extends BaseController {

    private static final Logger logger  = LoggerFactory.getLogger(PayOrderInfoController.class);

    @Reference(url= GlobalParam.CREDIT_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.CREDIT_DUBBO_SERVER_VERSION)
    private PayOrderInfoService payOrderInfoService;

    @Reference(url= GlobalParam.CREDIT_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.CREDIT_DUBBO_SERVER_VERSION)
    private RiskManagerInteractionService riskManagerInteractionService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public String loadPayOrderInfoList(Pager<PayOrderInfoVO> pager){//获取用户借款记录
        User user =getCurrentUser();
        List<PayOrderInfoVO> list=null;
        if( user!=null && SysStringUtils.isNotEmpty(user.getId())){
           list=payOrderInfoService.loadPayOrderInfoVOByUserId(pager,user.getId());
        }
        return success(list);
    }

    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    public String loadPayOrderInfoDetail(String orderNo, String mixCardNo){//获取用户借款记录详情
        PayOrderInfoVO payOrderInfoVO=null;
        if(SysStringUtils.isNotEmpty(orderNo)){
            PayOrderInfoForm payOrderInfoForm =new PayOrderInfoForm();
            payOrderInfoForm.setOrderNo(orderNo);
            payOrderInfoForm.setMixCardNo(mixCardNo);
            payOrderInfoVO = payOrderInfoService.loadVO(payOrderInfoForm);
        }
        return success(payOrderInfoVO);
    }
    @RequestMapping(value = "/RaiseLimit",method = RequestMethod.POST)
    public String RaiseLimit(){
        RaiseLimitRequest raiseLimitRequest=new RaiseLimitRequest();
        raiseLimitRequest.setOrderId("201707221644062891072");
        raiseLimitRequest.setStage(25+"");
        raiseLimitRequest.setBorrowType(1+"");
        raiseLimitRequest.setCustomerId("1vism");
        riskManagerInteractionService.raiseLimit(raiseLimitRequest);
       return success();
    }

    @RequestMapping(value = "/dealRiskSelect",method = RequestMethod.POST)
   public String dealRiskSelect(@RequestBody String data){
        logger.info("====================接受参数为" + data + "=============================");
       RiskSelectRequest riskSelectRequest= JSON.parseObject(data,RiskSelectRequest.class);
       RiskSelectResponse riskSelectResponse=payOrderInfoService.dealRiskSelect(riskSelectRequest);
       String str=JSON.toJSONString(riskSelectResponse);
       return str;
   }

    @RequestMapping(value = "/isNewOldTest",method = RequestMethod.POST)
   public String isNewOldTest(@RequestBody String data){
        logger.info("====================接受参数为" + data + "=============================");
        RiskSelectRequest riskSelectRequest= JSON.parseObject(data,RiskSelectRequest.class);
        String returnValues=payOrderInfoService.isnewOldSigns(riskSelectRequest.getUserId());
        RiskSelectResponse riskSelectResponse=new RiskSelectResponse();
        riskSelectResponse.setIsOverdue(returnValues);
        //String str=JSON.toJSONString(riskSelectResponse);
        return success(riskSelectResponse);
   }

}
